package com.example.purplestarcb.shoujizhushou;

import android.app.Fragment;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by PurpleStarCB on 2015/3/20.
 */
public class ProfileFragment extends Fragment {
    private SettingItemView sivUpdate;
    SharedPreferences sp;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View profile = inflater.inflate(R.layout.profile_layout, container, false);
        sp = this.getActivity().getSharedPreferences("config", Context.MODE_PRIVATE);
        sivUpdate = (SettingItemView) profile.findViewById(R.id.siv_update);
        final boolean update = sp.getBoolean("update", false);

        if(update){
            //自动升级已经开启
            sivUpdate.setChecked(true);
        }else{
            //自动升级已经关闭
            sivUpdate.setChecked(false);
        }
        sivUpdate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences.Editor editor = sp.edit();
                if (sivUpdate.isChecked()) {
                    //自动升级打开
                    sivUpdate.setChecked(false);
                    editor.putBoolean("update", false);

                } else {
                    //自动升级关闭
                    sivUpdate.setChecked(true);
                    editor.putBoolean("update", true);

                }

                editor.commit();
            }
        });
        return profile;
    }


}
